fix: support IdPs with 5 min token expiry and no refresh flow MONGOSH-2498 #232
+63
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is bordering on something we should consider an unsupported configuration, but since we know this is a real-world setup of some customers, let's try to support it.
Before this change, our OIDC plugin could exhibit undesirable behavior in a
specific configuration edge case, which, unfortunately, matches the default
behavior of at least one identity provider software.
Specifically, Ping Identity software does not typically provide us with
JWTs that are usable for authentication and authorization, so users may
opt to use ID tokens instead. Ping, however, by default does not provide
clients with new ID tokens on a refresh operations, and also only gives
those tokens a default validity of 5 minutes.
(We do recommend to Ping customers to enable passing new ID tokens on
refresh if they have this setup.)
However, 5 minutes also happens to be the time at which the plugin
prefers either refreshing tokens or prompting the user for re-authentication
instead of re-using tokens with a short leftover validity.
This means that when the driver requests a new token multiple times, or
multiple driver instances request tokens in quick succession (which can
easily happen, especially if they used the same token beforehand, which
obviously then expires at around the same time for each driver), the
plugin would try to refresh the token, then when that failed, prompt
the user for a new authentication attempt not just once every minutes,
but multiple times in quick succession as well.
To avoid this issue, we refactor the code that chooses a token acquisition
mechanism so that even if the current token still has a leftover validity
of less than 5 minutes and refreshing fails, we still keep using it until
the driver signals to us that it has become fully unusable.